Programming in CoffeeScript (Chris Mathews' Library) by Mark Bates

Programming in CoffeeScript (Chris Mathews' Library) by Mark Bates

Author:Mark Bates
Language: eng
Format: epub
Publisher: Addison-Wesley
Published: 2012-02-25T16:00:00+00:00


* * *

class Employee

constructor: ->

Employee.hire(@)

@hire: (employee) ->

@allEmployees ||= []

@allEmployees.push employee

@total: ->

console.log "There are #{@allEmployees.length} employees."

@allEmployees.length

class Manager extends Employee

@total: ->

console.log "There are 0 managers."

super

new Employee()

new Employee()

new Employee()

Manager.total()

* * *

Example: (source: class_level_super.js)

Click here to view code image

* * *

(function() {

var Employee, Manager,

__hasProp = Object.prototype.hasOwnProperty,

__extends = function(child, parent) { for (var key in parent) { if

(__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() {

this.constructor = child; } ctor.prototype = parent.prototype; child.prototype =

new ctor; child.__super__ = parent.prototype; return child; };



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.